package com.alibaba.citrus.cr.unified.inventory.handler;

import com.alibaba.citrus.cr.common.annotation.FacadeInvoker;
import com.alibaba.cloud.retail.delivery.api.model.delivery.request.fulfillment.CreateFulfillmentOrderOpenApiReq;
import com.alibaba.cloud.retail.delivery.api.model.delivery.request.fulfillment.CreateFulfillmentOrderReq;
import com.alibaba.cloud.retail.delivery.api.model.delivery.response.fulfillment.FulfillmentOrderOpenApiResponse;
import com.alibaba.cloud.retail.delivery.api.model.delivery.response.fulfillment.FulfillmentOrderResponse;
import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.crunifiedinventory.allocateconcurrenttest.service.AllocateConcurrentTestService;
import com.epoch.app.crunifiedinventory.model.dto.AllocateConcurrentRequest;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @description:
 * @author: yuhw
 * @date: 2024年03月15日 19:36
 **/
@Primary
@Service
public class AllocateConcurrentTestServiceImpl implements AllocateConcurrentTestService {
    private static Log log = Log.getLogger(AllocateConcurrentTestServiceImpl.class);
    @Resource
    private FulfillmentOrderOpenApi fulfillmentOrderOpenApi;

    @Override
    @FacadeInvoker
    public Result<Void> allocateConcurrentTest(AllocateConcurrentRequest allocateConcurrentRequest) {
        log.info("allocateConcurrentTest:{}", JSON.toJSONString(allocateConcurrentRequest));
        CreateFulfillmentOrderOpenApiReq req = new CreateFulfillmentOrderOpenApiReq();
        req.setRequestNo("111111111");
        com.alibaba.cloud.retail.delivery.api.model.delivery.response.Result<FulfillmentOrderOpenApiResponse> order = fulfillmentOrderOpenApi.createOrder(req);
        log.info("allocateConcurrentTest_result:{}", JSON.toJSONString(order));
        CreateFulfillmentOrderReq createFulfillmentOrderReq = new CreateFulfillmentOrderReq();
        createFulfillmentOrderReq.setRequestNo("KLIPMN");

        com.alibaba.cloud.retail.delivery.api.model.delivery.response.Result<FulfillmentOrderResponse> apiOrder = fulfillmentOrderOpenApi.createOrder(req());
        log.info("allocateConcurrentTest_result_3:{}",JSON.toJSONString(apiOrder));
        return Result.success(null);
    }

    private CreateFulfillmentOrderReq req(){
        String s = "{\"autoSubmit\":true,\"businessType\":\"11\",\"businessUnitCode\":\"6000\",\"channelCode\":\"90\",\"detailList\":[{\"close\":0,\"features\":\";outAllocateOrderLineId:20;\",\"materialCode\":\"130100000612\",\"productionDate\":\"2024-03-08\",\"quantity\":2.000,\"refOrderCreateTime\":\"2024-03-08 17:35:48\",\"refOrderLineNo\":\"2\",\"refOrderNo\":\"STO52024030850050046\",\"remark\":\"行备注\",\"saleQuantity\":2.000,\"salesUnitCode\":\"PC\",\"shippingUnitCode\":\"PC\",\"sourceOrderLineNo\":\"2\"}],\"expectedDeliveryTime\":\"2024-03-08 00:00:00\",\"features\":\";outAllocateOrderId:4860806939;transferOrderTargetLogicWarehouseCode:101791734;\",\"fromSys\":\"APP_SAP\",\"fulfillmentType\":100,\"innerCheckMark\":true,\"logicReceivingWarehouse\":\"武汉2号共享仓\",\"logicReceivingWarehouseCode\":\"101791734\",\"logicShippingWarehouse\":\"武汉1号共享仓\",\"logicShippingWarehouseCode\":\"100352078\",\"priority\":\"1\",\"productGroupCode\":\"11\",\"receivingWarehouse\":\"武汉1号仓\",\"receivingWarehouseCode\":\"420001\",\"refOrderType\":\"102\",\"remark\":\"主单备注\",\"requestNo\":\"edb9153e5a524eb086d4bc8043db3137\",\"salesOrganizationCode\":\"6000\",\"shipToPartyCode\":\"1906000016\",\"shippingMethodCode\":\"1\",\"shippingWarehouse\":\"武汉1号仓\",\"shippingWarehouseCode\":\"420001\",\"soldToPartyCode\":\"1906000016\",\"sourceOrderNo\":\"STO52024030850050046\"}";
        CreateFulfillmentOrderReq req = JSON.parseObject(s, CreateFulfillmentOrderReq.class);
        if (req == null){
            req = JSON.parseObject(JSON.toJSONString(s),CreateFulfillmentOrderReq.class);
        }
        return req;

    }
}
